#include<iostream>
#include<cstring>
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<unistd.h>

using namespace std;

int main()
{
  umask(0);
  int fi= open("bite",O_RDWR|O_CREAT,0666);
  if(fi<0)
  {
    cerr<<"open fail"<<endl;
    return -1;
  }
  
  const char* arr="i like linux!\n";
  //!!!!!!!!注意这里是strlen！不是sizeof
  int ret=write(fi,arr,strlen(arr));
  if(ret<0)
  {
    cerr<<"write fail!"<<endl;
    return -2;
  }
  //注意要偏移一下！！！文件指针的位置变了！
  lseek(fi, 0, SEEK_SET);//跳转读写位置到，从文件起始位置开始偏移0个字节
  char arr_read[128]={0};
  read(fi,arr_read,sizeof(arr_read));
  printf("%s",arr_read);
  close(fi);
  return 0;
}
